package com.pointlion.sys.mvc.admin.evaluate.remark;

import com.jfinal.aop.Before;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.pointlion.sys.mvc.common.model.Remark;
import com.pointlion.sys.mvc.common.model.SysUser;
import com.pointlion.sys.plugin.shiro.ShiroKit;

public class RemarkService{
	public static final RemarkService me = new RemarkService();
	public static final String TABLE_NAME = Remark.tableName;
	
	/***
	 * ����������ѯ
	 */
	public Remark getById(String id){
		return Remark.dao.findById(id);
	}
	
	/***
	 * ��ȡ��ҳ
	 */
	public Page<Record> getPage(int pnum,int psize,String name){
		String sql  = " from "+TABLE_NAME+" o LEFT JOIN sys_user p ON o.create_id = p.id where 1=1 " ;
		SysUser u = SysUser.dao.getById(ShiroKit.getUserId());
		if("1".equals(u.getIsAdmin())){

		}else{
			sql += "and o.create_id = '"+ShiroKit.getUserId()+"' ";
		}
		if(StrKit.notBlank(name)){
			sql += "and (p.name like '%"+name+"%' or p.username = '%"+name+"%') ";
		}
		sql += "order by o.create_time desc";
		return Db.paginate(pnum, psize, " select o.*,p.name ", sql);
	}
	
	/***
	 * ɾ��
	 * @param ids
	 */
	@Before(Tx.class)
	public void deleteByIds(String ids){
    	String idarr[] = ids.split(",");
    	for(String id : idarr){
    		Remark o = me.getById(id);
    		o.delete();
    	}
	}
}